package com.ruoyi.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.app.domain.AppMediumActivityUser;
import com.ruoyi.app.service.IAppMediumActivityUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/app/user")
public class AppMediumActivityUserController extends BaseController
{
    @Autowired
    private IAppMediumActivityUserService appMediumActivityUserService;

    /**
     * 查询活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）列表
     */
    @PreAuthorize("@ss.hasPermi('app:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppMediumActivityUser appMediumActivityUser)
    {
        startPage();
        List<AppMediumActivityUser> list = appMediumActivityUserService.selectAppMediumActivityUserList(appMediumActivityUser);
        return getDataTable(list);
    }

    /**
     * 导出活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）列表
     */
    @PreAuthorize("@ss.hasPermi('app:user:export')")
    @Log(title = "活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppMediumActivityUser appMediumActivityUser)
    {
        List<AppMediumActivityUser> list = appMediumActivityUserService.selectAppMediumActivityUserList(appMediumActivityUser);
        ExcelUtil<AppMediumActivityUser> util = new ExcelUtil<AppMediumActivityUser>(AppMediumActivityUser.class);
        util.exportExcel(response, list, "活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）数据");
    }

    /**
     * 获取活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:user:query')")
    @GetMapping(value = "/{activityUserId}")
    public AjaxResult getInfo(@PathVariable("activityUserId") Long activityUserId)
    {
        return success(appMediumActivityUserService.selectAppMediumActivityUserByActivityUserId(activityUserId));
    }

    /**
     * 新增活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）
     */
    @PreAuthorize("@ss.hasPermi('app:user:add')")
    @Log(title = "活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppMediumActivityUser appMediumActivityUser)
    {
        return toAjax(appMediumActivityUserService.insertAppMediumActivityUser(appMediumActivityUser));
    }

    /**
     * 修改活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）
     */
    @PreAuthorize("@ss.hasPermi('app:user:edit')")
    @Log(title = "活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppMediumActivityUser appMediumActivityUser)
    {
        return toAjax(appMediumActivityUserService.updateAppMediumActivityUser(appMediumActivityUser));
    }

    /**
     * 删除活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）
     */
    @PreAuthorize("@ss.hasPermi('app:user:remove')")
    @Log(title = "活动与用户的关联关系（无物理外键，通过业务逻辑维护关联）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityUserIds}")
    public AjaxResult remove(@PathVariable Long[] activityUserIds)
    {
        return toAjax(appMediumActivityUserService.deleteAppMediumActivityUserByActivityUserIds(activityUserIds));
    }
}
